define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'setting/openstatus/index',
                    add_url: 'setting/openstatus/add',
                    edit_url: 'setting/openstatus/edit',
                    del_url: 'setting/openstatus/del',
                    multi_url: 'setting/openstatus/multi',
                    table: 'openstatus',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                onEditableSave: function (field, row, oldValue, $el) {
             
                var curRow = {};
                
                curRow['row['+field+']'] = row[field];

                    $.ajax({
                        type: 'POST',
                        url: $.fn.bootstrapTable.defaults.extend.edit_url+"/ids/"+row.id,
                        data:curRow,
                        dataType: 'JSON',
                        success: function (data, textStatus, jqXHR) {
                            if(data.code =='1'){
                                
                                table.bootstrapTable('refresh', Table.api.init);
                            }else{

                                alert(data.msg);
                            }
                           
                        },
                        error: function () { alert("error");
                    }
                    });
                },
                editable:true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'is_open', title: __('Is_open'), visible:false, searchList: {"0":__('Is_open 0'),"1":__('Is_open 1')}},
                        // {field: 'is_open_text', title: __('Is_open'), operate:false},
                        {field: 'is_open',title: __('Is_open'),editable:{
                            type: 'select',
                            is_edit: true,
                            inputclass:'co-b',
                            source: [
                              
                                {value: 1, text: '打开'},
                                {value: 0, text: '关闭'},
                               
                                ],
                            
                        } },
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});